package com.hopes.bizz.risk.transfer.mq;


import com.hopes.bizz.risk.activemq.log.ActiveMqLogger;
import com.hopes.bizz.risk.transfer.constant.RiskConstant;
import com.hopes.boss.common.core.constant.CommonConstants;
import lombok.extern.slf4j.Slf4j;
import org.springframework.jms.core.JmsMessagingTemplate;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import javax.jms.DeliveryMode;
import javax.jms.Queue;
import javax.jms.Session;
import java.util.Date;


@Component
@Slf4j
public class RiskDataProducer {

    @Resource
    private ActiveMqLogger logger;

    @Resource
    private JmsMessagingTemplate jmsMessagingTemplate;

    @Resource
    private Queue riskQueue;

    public void sendMsg(String message) {
        try {
            jmsMessagingTemplate.convertAndSend(riskQueue, message);
            logger.saveTenantMqLog(true, message, new Date(), RiskConstant.KEY_QUEUE_RISK, null,
                    DeliveryMode.PERSISTENT, Session.AUTO_ACKNOWLEDGE, null, null);
        } catch (Exception e) {
            log.error("消息发送失败,原因={}", e.getMessage());
            logger.saveTenantMqLog(false, message, new Date(), CommonConstants.KEY_QUEUE_UNIPUSH, null,
                    DeliveryMode.PERSISTENT, Session.AUTO_ACKNOWLEDGE, null, e.getMessage());
        }
    }
}
